/*
 * Created on 07.10.2005
 *
 * To change the template for this generated file go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
package de.fmannan.addbook.editor.util;


public class BooleanUtil {

    private BooleanUtil() {
        // Util is not instantiable.
    }

    
    public static String formatBoolean(boolean value)
    {
        String result;
        if ( value ) {
            result = Messages.getString("BooleanUtil.TrueLabel"); //$NON-NLS-1$
        }
        else {
            result = Messages.getString("BooleanUtil.FalseLabel"); //$NON-NLS-1$
        }
        return result;
    }

    public static boolean parseBoolean(String booleanString) 
    {
        boolean result;
        
        if ( booleanString != null ) {
            if ( booleanString.equalsIgnoreCase(Messages.getString("BooleanUtil.TrueLabel"))) { //$NON-NLS-1$
                result = true;
            }
            else if ( booleanString.equalsIgnoreCase(Messages.getString("BooleanUtil.FalseLabel"))) { //$NON-NLS-1$
                result = false;
            }
            else {
                String message = Messages.getString("BooleanUtil.NotParseableMessage") + booleanString + //$NON-NLS-1$
                    Messages.getString("BooleanUtil.DetailsFirstPart") + Messages.getString("BooleanUtil.TrueLabel") +  //$NON-NLS-1$ //$NON-NLS-2$
                    Messages.getString("BooleanUtil.DetailsMiddlePart") + Messages.getString("BooleanUtil.FalseLabel") + Messages.getString("BooleanUtil.DetailsEndPart"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                    
                throw new IllegalArgumentException(message);
            }
        }
        else {
            String message = Messages.getString("BooleanUtil.NoValueMessage") +  //$NON-NLS-1$
            Messages.getString("BooleanUtil.DetailsFirstPart") + Messages.getString("BooleanUtil.TrueLabel") +  //$NON-NLS-1$ //$NON-NLS-2$
            Messages.getString("BooleanUtil.DetailsMiddlePart") + Messages.getString("BooleanUtil.FalseLabel") + Messages.getString("BooleanUtil.DetailsEndPart"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            throw new IllegalArgumentException(message);
        }
        return result;
    }
    
}
